#include <linux/kernel.h>
#include <linux/orientation.h>
#include <linux/syscalls.h>
#include <linux/uaccess.h>
#include <linux/module.h>	/* Specifically, a module */
#include <linux/proc_fs.h>	/* Necessary because we use proc fs */
#include <linux/sched.h>	/* For putting processes to sleep and waking them up */
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <linux/time.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/paravirt.h>


/* Map the current processes' page table into userspace.
 * After successfully completing this call, addr will contain the current process's
 * page directory, followed by the current process's page table indexed by page 
 * number with each index containing the corresponding page table entry for
 * that page number (i.e. virtual address).
 * @addr A previously mmap'ed memory region prepped for use
 *       with this system call. A wrapper has been provided
 *       for you to prep this memory region.
 * system call number 369.
 */
SYSCALL_DEFINE1(expose_page_table, void __user *, addr)
{
	int i,j,k;
	pgd_t pgd*;
	pmd_t pmd*;
	pte_t pte*;
	unsigned long cr3;
	int entry_size = 64;
	
	printk("expose_page_table:%n");
	
	pgd_size=2048;//2048*64bit entries
	cr3 = read_cr3();
	
	for(i=0;i<PTRS_PER_PGD;i++){
		//1st level PDG
		pgd = pgd_offset(vm_mm, cr3+i*entry_size);
		for(j=0;j<PTRS_PER_PMD;j++){
			pmd = pmd_offset(pgd+j*entry_size);
			for(k=0;k<PTRS_PER_PTE;k++){
				pte = pte_offset_kernel(pmd,cr3+j*entry_size);
				remap_pfn_range(vm_mm->mmap, cr3, pte_pfn(pte),1<<PAGE_SHIFT,0);
			}
		}
	}
	
	
	return 0;
}





